Microsoft Foundation Classes (mfc.hlp) (Table of Contents; Topic list)
CObArray::operator []
CObArray                                    Up Contents Index Back
──Microsoft Foundation Classes──────────────────────────────────────────────
 
  CObject*& operator []( int nIndex );
  CObject* operator []( int nIndex ) const;
 
  Remarks
 
  These subscript operators are a convenient substitute for the SetAt and
  GetAt functions.
 
  The first operator, invoked for arrays that are not const, may be used
  on either the right (r-value) or the left (l-value) of an assignment
  statement. The second, invoked for const arrays, may be used only on the
  right.
 
  The Debug version of the library asserts if the subscript (either on the
  left or right side of an assignment statement) is out of bounds.
 
  Example
 
  CObArray array;
  CAge* pa;
 
  array.Add( new CAge( 21 ) ); // Element 0
  array.Add( new CAge( 40 ) ); // Element 1
  pa = (CAge*)array[0]; // Get element 0
  ASSERT( *pa == CAge( 21 ) ); // Get element 0
  array[0] = new CAge( 30 ); // Replace element 0
  delete pa;
  ASSERT( *(CAge*) array[0] == CAge( 30 ) ); // Get new element 0
 
 
  See Also
 
  CObArray::GetAt, CObArray::SetAt
 
 
                                     -♦-